﻿

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Collections;


namespace AUI
{
    public class tbl_OrderTypes_Info : Standard_Info
    {
        public int OrderTypeId { get; set; }
        public string OrderTypeCode { get; set; }
        public string OrderTypeName { get; set; }
        public DateTime CreateDate { get; set; }
        public string CreateUser { get; set; }
        public DateTime LastUpdate { get; set; }
        public string LastUser { get; set; }
    }
    public class tbl_OrderTypes_Length
    {
        public static int OrderTypeCode = 2;
        public static int OrderTypeName = 256;
    }
    public class tbl_OrderTypes_Controller
    {
        #region "Contructor"

        private static tbl_OrderTypes_Controller _instance;

        protected tbl_OrderTypes_Controller() { }

        protected void Dispose()
        {
            _instance = null;
        }

        private static object _syncLock = new object();

        public static tbl_OrderTypes_Controller Instance()
        {
            if (_instance == null)
            {
                lock (_syncLock)
                {
                    if (_instance == null)
                        _instance = new tbl_OrderTypes_Controller();
                }
            }
            return _instance;
        }

        #endregion

        public DataTable GetList(out int ItemCount, string orderBy, string orderDirection, int currentPage, int pageSize, string keyWord)
        {
            DataTable retVal = null;
            ItemCount = 0;
            DataSet ds = DataConnect.ExecuteDataset("prc_OrderTypes_GetList", orderBy, orderDirection, currentPage, pageSize, keyWord);
            if (ds != null)
            {
                retVal = ds.Tables[0];
                if (ds.Tables[1] != null)
                    ItemCount = Globals.ToInt32(ds.Tables[1].Rows[0][0]);
            }
            return retVal;
        }
        public DataTable GetAll()
        {
            return DataConnect.ExecuteDatatable("prc_OrderTypes_GetAll");
        }

        public bool Delete(int OrderTypeId)
        {
            return (Globals.ToInt32(DataConnect.ExecuteNonQuery("prc_OrderTypes_Delete", OrderTypeId)) > 0);
        }

        public bool IsExist(tbl_OrderTypes_Info i)
        {
            return (Globals.ToInt32(DataConnect.ExecuteScalar("prc_OrderTypes_Exists", i.OrderTypeId, i.OrderTypeCode)) > 0);
        }

        public int Save(tbl_OrderTypes_Info i)
        {
            int retVal = 0;
            if (i.OrderTypeId == 0)
                retVal = Globals.ToInt32(DataConnect.ExecuteScalar("prc_OrderTypes_Insert", i.OrderTypeCode,
                        i.OrderTypeName,
                        i.CreateUser));
            else
            {
                if (DataConnect.ExecuteNonQuery("prc_OrderTypes_Update", i.OrderTypeId, i.OrderTypeCode,
                        i.OrderTypeName,
                        i.LastUser) > 0)
                    retVal = i.OrderTypeId;
            }
            return retVal;
        }

        public tbl_OrderTypes_Info GetInfo(int OrderTypeId)
        {
            tbl_OrderTypes_Info retVal = null;
            DataTable dt = DataConnect.ExecuteDatatable("prc_OrderTypes_GetInfo", OrderTypeId);
            if (dt != null)
                foreach (DataRow dr in dt.Rows)
                {
                    retVal = new tbl_OrderTypes_Info();
                    retVal.FillDataProperty(dr);
                }
            return retVal;
        }
    }
}
